package com.toune.movie.mvp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.toune.movie.R;
import com.toune.movie.base.Api;
import com.toune.movie.base.AppConstant;
import com.toune.movie.base.BaseFragment;
import com.toune.movie.mvp.activity.WebActivity;
import com.toune.movie.mvp.contract.MovieTvContract;
import com.toune.movie.mvp.presenter.MovieTvPresenter;

import java.util.Random;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/5/9.
 */

public class MovieTvFragment extends BaseFragment<MovieTvPresenter> implements MovieTvContract.View {
    private static MovieTvFragment fragment;
    @BindView(R.id.web1_btn)
    Button web1Btn;
    @BindView(R.id.web2_btn)
    Button web2Btn;
    @BindView(R.id.web3_btn)
    Button web3Btn;
    @BindView(R.id.web_btn)
    Button webBtn;

    public static MovieTvFragment newInstance() {
        if (fragment == null) {
            fragment = new MovieTvFragment();
        }
        return fragment;
    }

    @Override // 实例化presenter
    public MovieTvPresenter initPresenter() {
        return new MovieTvPresenter();
    }

    @Override
    public void loadMore() {

    }

    @Override
    public void refreData() {
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        Random random = new Random();
        webBtn.setBackgroundColor(AppConstant.COLOR_DATAS[random.nextInt(AppConstant.COLOR_DATAS.length)]);
        web1Btn.setBackgroundColor(AppConstant.COLOR_DATAS[random.nextInt(AppConstant.COLOR_DATAS.length)]);
        web2Btn.setBackgroundColor(AppConstant.COLOR_DATAS[random.nextInt(AppConstant.COLOR_DATAS.length)]);
        web3Btn.setBackgroundColor(AppConstant.COLOR_DATAS[random.nextInt(AppConstant.COLOR_DATAS.length)]);
    }

    @Override
    public void init(Bundle savedInstanceState) {
//        Random random = new Random();
//        webBtn.setBackgroundColor(Api.COLOR_DATAS[random.nextInt(Api.COLOR_DATAS.length)]);
//        web1Btn.setBackgroundColor(Api.COLOR_DATAS[random.nextInt(Api.COLOR_DATAS.length)]);
//        web2Btn.setBackgroundColor(Api.COLOR_DATAS[random.nextInt(Api.COLOR_DATAS.length)]);
//        web3Btn.setBackgroundColor(Api.COLOR_DATAS[random.nextInt(Api.COLOR_DATAS.length)]);
        //隐藏天天直播
        web3Btn.setVisibility(View.GONE);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_movie_tv;
    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void useNightMode(boolean isNight) {

    }

    @OnClick({R.id.web_btn, R.id.web1_btn, R.id.web2_btn, R.id.web3_btn})
    public void onViewClicked(View view) {
        String url = "https://www.bttwo.com/tv";
        switch (view.getId()) {
            case R.id.web_btn:
                url = "http://www.52xsba.com/zhibo.php";
                break;
            case R.id.web1_btn:
                url = "http://www.52xsba.com/zhibo2.php";
                break;
            case R.id.web2_btn:
                url = "https://www.bttwo.com/tv";
                break;
            case R.id.web3_btn:
                url = "http://www.tiantianzhibo.net/";
                break;
        }
        Intent intent = new Intent(getContext(), WebActivity.class);
        intent.putExtra("url", url);
        startActivity(intent);
    }
}
